home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / readers / skim-0.8 / skim-0 / skim-0.8.4 / SetTest.c < prev    next >
C/C++ Source or Header  |  1996-02-18  |  2KB  |  87 lines

  1. /*
  2.  * NAME
  3.  *   SetTest.c
  4.  * DESCRIPTION
  5.  *   Test the Set class. Run this test by typing 'make test' in the source
  6.  *   directory of skim.
  7.  * COPYRIGHT
  8.  *   Copyright (C) 1996  Rene W.J. Pijlman
  9.  *
  10.  *   This program is free software; you can redistribute it and/or modify
  11.  *   it under the terms of the GNU General Public License as published by
  12.  *   the Free Software Foundation; either version 2 of the License, or
  13.  *   (at your option) any later version.
  14.  *
  15.  *   This program is distributed in the hope that it will be useful,
  16.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *   GNU General Public License for more details.
  19.  *
  20.  *   You should have received a copy of the GNU General Public License
  21.  *   along with this program; if not, write to the Free Software
  22.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  * VERSION
  24.  *   $Header: /home/rene/sys/CVS_MasterSourceRepository/skim/SetTest.c,v 1.3 1996/02/18 11:40:23 rene Exp $
  25.  *   Distributed with Skim version 0.8.4.
  26.  */
  27.  
  28. #include "Set.h"
  29. #include "StandardIO.h"
  30. #include "MemAlloc.h"
  31.  
  32. #include <assert.h>
  33. #include <string.h>
  34.  
  35. /* assert()'s must be in effect in this file. */
  36. #ifdef NDEBUG
  37. #    undef NDEBUG
  38. #endif
  39.  
  40. static void TestCreation( Set * Set1, Set * Set2 )
  41. {
  42.     SetDestroy( SetCreate( (SetElementCompareFunction)abort,
  43.                            (SetElementDestroyFunction)abort ) );
  44.  
  45.     *Set1 = SetCreate( (SetElementCompareFunction)strcmp, MemFree );
  46.     *Set2 = SetCreate( (SetElementCompareFunction)strcasecmp, MemFree );
  47.  
  48.     assert( SetNumberOfElements(*Set1) == 0 );
  49.     assert( SetNumberOfElements(*Set2) == 0 );
  50. }
  51.  
  52. static void TestFind( Set Set1, Set Set2 )
  53. {
  54.     assert( SetNumberOfElements(Set1) == 0 );
  55.     assert( SetNumberOfElements(Set2) == 0 );
  56.  
  57.     SetAddElement( Set1, MemNewString("Aaa") );
  58.     SetAddElement( Set2, MemNewString("Bbb") );
  59.  
  60.     assert( SetNumberOfElements(Set1) == 1 );
  61.     assert( SetNumberOfElements(Set2) == 1 );
  62.  
  63.     SetFindElement( Set1, "aaa" );
  64.     SetFindElement( Set2, "bbb" );
  65.  
  66.     assert( !SetElementExists(Set1) );
  67.     assert( SetElementExists(Set2) );
  68.     assert( !strcmp("Bbb", (char *)SetGetElement(Set2)) );
  69. }
  70.  
  71. int main( void )
  72. {
  73.     Set Set1;
  74.     Set Set2;
  75.  
  76.     TestCreation( &Set1, &Set2 );
  77.  
  78.     TestFind( Set1, Set2 );
  79.  
  80.     SetDestroy( Set1 );
  81.     SetDestroy( Set2 );
  82.  
  83.     SIOPrintf( StandardOutput, "OK\n" );
  84.  
  85.     return EXIT_SUCCESS;
  86. }
  87.